Vue.component("chargecode", {
  data() {
    return {
      tabledata: [],
      datebe: [],
      snum: '',
      schips: '',
      sbstr: "P",
      sdate: "",
      rebatetype: []
    }
  },
  props: ["path", "col", "showitem", "pval", "vt"],
  template: `<div style="margin:20px;">
      <el-input placeholder="生成数量" v-model="snum"></el-input>
      <el-input placeholder="游戏币" v-model="schips"></el-input>
      <el-input placeholder="开始字符" v-model="sbstr"></el-input>
      <el-date-picker placeholder="有效日期" v-model="sdate" type="date"></el-date-picker>
      <el-button type="primary" plain @click="send()">生成体检卡</el-button><br/><br/>
      <el-date-picker v-model="datebe" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd""></el-date-picker>
      <el-button type="primary" plain @click="opendata()">查询</el-button>
      <el-table :data="tabledata" style="width: 100%">
        <el-table-column v-for="(item,index) in col" :prop="index" :label="item"></el-table-column>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="showdetail(scope.row)" type="text" size="small">导出</el-button>
            <el-button @click="delbatch(scope.row)" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>`,
  methods: {
    opendata: function() { //请求数据
      let $this = this;
      http.get("/ajax/" + this.path + "?B=" + (this.datebe[0] || "") + "&E=" + (this.datebe[1] || "")).then(function(res) {
          $this.tabledata = res.data;
      });
    },
    send: function(){ //奖励发放
      let $this = this;
      http.get("/ajax/" + this.path + "?N=" + this.snum + "&C=" + this.schips + "&B=" + this.sbstr + "&T=" + this.sdate).then(function(res) {
        $this.$message({message: res.data.m});
        $this.opendata();
      });
    },
    showdetail: function(row){
      /*let $this = this;
      http.get("/ajax/" + this.path + "?batch=" + row.batch).then(function(res) {
        //定义文件内容，类型必须为Blob 否则createObjectURL会报错 
        let content = new Blob([res.data.view]) 
        //生成url对象 
        let urlObject = window.URL || window.webkitURL || window  
        let url = urlObject.createObjectURL(content)  
        //生成<a></a>DOM元素 
        let el = document.createElement('a') 
        //链接赋值 
        el.href = url 
        el.download ="out.csv"
        //必须点击否则不会下载 
        el.click()  
        //移除链接释放资源  
        urlObject.revokeObjectURL(url) 
      });*/
      window.open("/ajax/" + this.path + "?batch=" + row.batch);
    },
    delbatch: function(row){
      let $this = this;
      http.get("/ajax/" + this.path + "?a=del&batch=" + row.batch).then(function(res){
        $this.opendata();
      });
    }
  },
  created: function () {
    console.log("created ", this.path);
    this.opendata();
  }
});